package com.example.keli.ui.home.activity;

import android.app.Activity;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.example.keli.R;
import com.example.keli.base.BaseActivity;
import com.example.keli.ui.home.model.TabPosition;
import com.flyco.roundview.RoundTextView;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class TabMoreActivity extends BaseActivity {

    @BindView(R.id.close)
    ImageView close;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;

    public static void start(Activity context, ArrayList<String> sTitle) {
        Intent intent = new Intent(context, TabMoreActivity.class);
        intent.putStringArrayListExtra("tab", sTitle);
        context.startActivityForResult(intent,100);
    }

    @Override
    protected int layoutId() {
        return R.layout.activity_tab_more;
    }

    @Override
    protected void bindData() {
        abTitle.setText("首页");
        ArrayList<String> sTitle = getIntent().getStringArrayListExtra("tab");
        sTitle.remove(0);
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(4,StaggeredGridLayoutManager.VERTICAL));
        TabAdapter adapter = new TabAdapter(sTitle);
        recyclerView.setAdapter(adapter);

        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                EventBus.getDefault().post(new TabPosition(position));
                finish();
            }
        });
    }

    @OnClick(R.id.close)
    public void onViewClicked() {
        finish();
    }

    public class TabAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
        public TabAdapter(List<String> mData) {
            super(R.layout.item_tab, mData);
        }

        @Override
        protected void convert(BaseViewHolder helper, String text) {
            RoundTextView roundTextView = helper.getView(R.id.roundtext);
            roundTextView.setText(text);
        }
    }
}
